<?php
	#############################################################################################
	# Programmer: สมบูรณ์  กองลี																#
	# Email		: hugo8xx@hotmail.com.															#
	#############################################################################################
	
	if (!defined('BASE_ABS')) exit('No direct script access allowed');

	function warpThai($str, $offset, $fix=" ...", $length=0) {
		return iconv_substr($str, $offset, $length, 'UTF-8'). $fix;
	}
	
	function stripBlank($str){
		return strtolower(preg_replace('/ /','-',strip_tags($str)));	
	}
	
	function toPercent($num) {
		return sprintf('%02.2f', $num);
	}

	function warpMore($text,$link,$label="อ่านต่อ") {
		$markWarp = "<div style=\"page-break-after: always(.*)\"><span style=\"display: none(.*)\">&nbsp;<\/span><\/div>";
		$mark = $markWarp;
		$text = preg_replace("/\r|\n/", "--NNN--", $text); 
		$text = preg_replace("/(.*)$mark(.*)/", "$1 <a href='$link' class='more'>$label</a>", $text); 

		return preg_replace("/--NNN--/","\n", $text);
	}

	function keyword($str) {
		$str = strip_tags($str);
		$str = preg_replace("/\r|\n/", "", $str);
		$str = preg_replace("/\{(.*?)\}/", "", $str);
		$str = preg_replace("/\s+/", " ", $str);
		return mysql_escape_string($str);
	}
	
	function format_price($val){
		if(strlen($val) <= 3 ){return $val;}
		$n = 0;
		$result = "";
		for($i = strlen($val) - 1;$i >= 0;$i--){
			if ($n == 3){
				$result = ",$result";
				$n = 0;
			}
			$n++;
			$result = $val[$i].$result;
		}
		return $result;
	};

	
?>